package com.roc.dao.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.roc.dao.DaoException;
import com.roc.dao.IAnnounceDao;
import com.roc.pojo.Announcement;
import com.roc.util.Constance;


@Repository
public class AnnounceDaoImpl extends BaseDaoImpl implements IAnnounceDao{

	@Override
	public List<Announcement> queryNewAnnouncement() throws DaoException {
		// TODO Auto-generated method stub
		List<Announcement> annList = new ArrayList<Announcement>();
		List<Object> obL=new ArrayList<Object>() ;
	//	Object[] ob;
		try{
			Session session =sessionFactory.getCurrentSession(); 
			String sql="SELECT * FROM t_Announcements a order by a.dt_create desc  ";
			SQLQuery query = session.createSQLQuery(sql);
			
			//obL = (List<Object>) query.list();
		//	Iterator iterator=(Iterator) query.list().iterator();
			obL=query.list();
			if(obL.size()>0 && obL!=null){
				Iterator iterator=obL.iterator();
				int i=0;
			    while(iterator.hasNext()){
					Announcement annunce=new Announcement();
					Object[] ob=(Object[])iterator.next();
					annunce.setId(Long.parseLong(Constance.Null2EmptyTrim(ob[0].toString())));
					annunce.setTitle(Constance.Null2EmptyTrim(ob[1].toString()));
					if(Constance.Null2EmptyTrim(ob[1].toString()).equals("")){
						annunce.setContent("");
					}else{
						annunce.setContent(ob[2].toString());
					}
					
					annunce.setOperators(Constance.Null2EmptyTrim(ob[3].toString()));
					annList.add(annunce);
					i++;
					if(i>=3){
						break;
					}
			    }
			}
			
			//ann.setDtCreate(ob[4].toString());
			//ann.setDtLostmod(ob[5].toString());
			//ann=(Announcement) ob;
			//ann=(Announcement) ob;
		}catch(Exception e){
			logger.debug(e.getMessage(), e);
			throw new DaoException("查询失败！");
		}
		return annList;
	}

}
